﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UIManager : MonoSingleton<UIManager> {
    private Transform canvas;
    /// <summary>
    /// 保存打开的UI
    /// </summary>
    private Dictionary<string, Transform> UIlist = new Dictionary<string, Transform>();
    /// <summary>
    /// UI存放的路径，
    /// </summary>
    private string uiPath="Prefabs/UI/";
    private void Start()
    {
        Init();
    }
    private void Init()
    {
        canvas = GameObject.Find("Canvas").transform;
    }
    /// <summary>
    /// 打开UI，参数为UI名字，不用完整路径
    /// </summary>
    /// <param name="Uiname"></param>
    public void OpenUI(string Uiname)
    {
        if (!canvas)
        {
            Init();
        }
        //GameObject openUI= ObjectPool.Instance.OutPool(uiPath+Uiname,canvas);
        GameObject ui = Instantiate(Resources.Load(uiPath + Uiname) as GameObject, canvas);
        UIlist.Add(Uiname, ui.transform);
    }
    /// <summary>
    /// 关闭指定的UI
    /// </summary>
    /// <param name="uiname"></param>
    public void CloseUI(string uiname)
    {
        if (UIlist.ContainsKey(uiname))
        {
            //ObjectPool.Instance.InPool(UIlist[uiname]);
            Destroy(UIlist[uiname].gameObject);
            UIlist.Remove(uiname);
            return;
        }
        Debug.Log("没有该UI:["+uiname+"]");
    }
}
